import axios from 'axios';
import parse from 'parse-link-header';

axios.defaults.baseURL = 'http://localhost:6341';

// 添加请求拦截器
axios.interceptors.request.use(
  (config) => config,
  (error) => Promise.reject(error),
);

// 添加响应拦截器
axios.interceptors.response.use(
  (response) => {
    const { link } = response.headers;
    let result;
    if (link) {
      result = parse(link);
    }
    return { ...response, pagination: { ...result } };
  },
  (error) => Promise.reject(error),
);

axios.interceptors.response.use(
  (response) => response,
  (error) => Promise.reject(error),
);

export default axios;
